/** the format of the parse SQL quer, also see readme file **/

package qp.utils;

import java.util.Vector;

public class SQLQuery
{

	Vector projectList; // List of project attributes from select clause
	Vector fromList; // List of tables in from clause
	Vector conditionList; // List of conditions appeared in where clause

	/**
	 * represent again the the selection and join conditions in separate lists
	 **/

	Vector selectionList; // List of select predicates
	Vector joinList; // List of join predicates

	Vector groupbyList; // List of attibutes in groupby clause
	
	boolean isDistinct = false; // Whether distinct key word appeared in select
								// clause

	public Vector orderbyList; // *********add by ZJX
	
	public Vector orderbyAttributelist;// *********add by ZJX
	public Vector AscOrDesclist;//************add by ZJX
	
	
	public SQLQuery(Vector list1, Vector list2, Vector list3, Vector list4)
	{
		projectList = list1;
		fromList = list2;
		conditionList = list3;
		orderbyList = list4;  //*****************
		splitConditionList(conditionList);
        splitOrderbyList(orderbyList);
	}

	public SQLQuery(Vector list1, Vector list2, Vector list3)
	{
		projectList = list1;
		fromList = list2;
		conditionList = list3;
		groupbyList = null;
		orderbyList = null;
		splitConditionList(conditionList);
	}

	// 12 july 2003 (whtok)
	// Constructor to handle no WHERE clause case
	public SQLQuery(Vector list1, Vector list2)
	{
		projectList = list1;
		fromList = list2;
		conditionList = null;
		groupbyList = null;
		orderbyList = null;
		joinList = new Vector();
		selectionList = new Vector();
	}

	/** split the condition list into selection, and join list **/

	protected void splitConditionList(Vector tempVector)
	{
		selectionList = new Vector();
		joinList = new Vector();
		for (int i = 0; i < tempVector.size(); i++)
		{
			Condition cn = (Condition) tempVector.elementAt(i);
			if (cn.getOpType() == Condition.SELECT)
				selectionList.add(cn);
			else
				joinList.add(cn);
		}
	}

	public void splitOrderbyList(Vector orderbylist)
	{
		orderbyAttributelist=new Vector();
		AscOrDesclist=new Vector();
		for (int i = 0; i < orderbylist.size(); i++)
		{
			Order or = (Order) orderbylist.elementAt(i);
			orderbyAttributelist.add(or.getAttribute());
			AscOrDesclist.add(or.getAscOrDesc());
		}
	}
	
	
	public void setIsDistinct(boolean flag)
	{
		isDistinct = flag;
	}

	public boolean isDistinct()
	{
		return isDistinct;
	}

	public Vector getProjectList()
	{
		return projectList;
	}

	public Vector getFromList()
	{
		return fromList;
	}

	public Vector getConditionList()
	{
		return conditionList;
	}

	public Vector getSelectionList()
	{
		return selectionList;
	}

	public Vector getJoinList()
	{
		return joinList;
	}

	public void setGroupByList(Vector list)
	{
		groupbyList = list;
	}

	public Vector getGroupByList()
	{
		return groupbyList;
	}

	public int getNumJoin()
	{
		if (joinList == null)
			return 0;

		return joinList.size();
	}

	// ************the following is added by ZJX
	public void setOrderbylist(Vector orderbylist)
	{
		this.orderbyList = orderbylist;
		splitOrderbyList(orderbylist);
	}

	public Vector getOrderbylist()
	{
		return this.orderbyList;
	}
	
	public void setOrderbyattrilist(Vector orderbyattrilist)
	{
		this.orderbyAttributelist = orderbyattrilist;
	}

	public Vector getOrderbyAttrilist()
	{
		return this.orderbyAttributelist;
	}
	
	public void setAscOrDesclist(Vector list)
	{
		this.AscOrDesclist = list;
	}

	public Vector getAscOrDesclist()
	{
		return this.AscOrDesclist;
	}
	
}
